function seg_mean=myPAA(data, segnum)

if mod(size(data,2),segnum)~=0
    disp 'not divisible completely'
    return;
end

seglength=size(data,2)/segnum;
seg_mean=[];
for s=1:segnum
    temp=data(:,(s-1)*seglength+1:s*seglength);
    seg_mean=[seg_mean (mean(temp'))'];
end

%approximate according to breakpoints defined by "fidning motifs in time series"
%breakpoints=[-0.84 -0.25 0.25 0.84]';
breakpoints=[-1.07 -0.57 -0.18 0.18 0.57 1.07]';
r=size(seg_mean,1);
c=size(seg_mean,2);

for i=1:r
    for j=1:c
        [closest_k_matches]=closestKwith(seg_mean(i,j),breakpoints,1);
        seg_mean(i,j)=breakpoints(closest_k_matches);
    end
end